<?php

namespace app\merchant\controller;

use think\Db;

class Area extends Common
{
    public function getCityTree()
    {
        $pros = Db::name('provinces')->field('province as text, provinceid as id')->where('id','not in',[32,33,34])->select();
        foreach ($pros as $k => $v) {
            $pros[$k]['icon'] = 'none';
            $pros[$k]['state'] = ['opened' => false];  //jstree需要
            $city = Db::name('cities')->where('provinceid', $v['id'])->field('city as text, cityid as id')->select();
            foreach ($city as $kk => $vv) {
                $city[$kk]['icon'] = 'none';
                $city[$kk]['state'] = ['opened' => false];
            }
            $pros[$k]['children'] = $city;
        }
        return json($pros);
    }

    public function getAreaTree()
    {
        $pros = Db::name('provinces')->field('province as text, provinceid as id')->select();
        foreach ($pros as $k => $v) {
            $pros[$k]['icon'] = 'none';
            $pros[$k]['state'] = ['opened' => true];  //jstree需要
            $city = Db::name('cities')->where('provinceid', $v['id'])->field('city as text, cityid as id')->select();
            foreach ($city as $kk => $vv) {
                $city[$kk]['icon'] = 'none';
                //$city[$kk]['state'] = ['opened' => true];
                $area = Db::name('areas')->where('cityid', $vv['id'])->where('area', 'neq', '市辖区')->field('area as text, areaid as id')->select();
                foreach ($area as $kkk => $vvv) {
                    $area[$kkk]['icon'] = 'none';
                }
                $city[$kk]['children'] = $area;
            }
            $pros[$k]['children'] = $city;
        }
        return json($pros);
    }
}
